package com.itheima.demo;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class Demo_HashMap003 {
    public static void main(String[] args) {
        //创建一个集合容器;
        HashMap<String, String> map = new HashMap<>();
        //往集合中添加元素;
        map.put("1号丈夫", "1号妻子");
        map.put("2号丈夫", "2号妻子");
        map.put("3号丈夫", "3号妻子");
        map.put("4号丈夫", "4号妻子");
        map.put("5号丈夫", "5号妻子");
        //获取集合中的每一个键;
        Set<String> keys = map.keySet();
        //使用增强for遍历;
        for (String key : keys) {
            String value = map.get(key);
            System.out.println(key + "==" + value);
        }
        System.out.println("============");
        //使用迭代器遍历;
        Iterator<String> it = keys.iterator();
        while (it.hasNext()) {
            String key = it.next();
            String value = map.get(key);
            System.out.println(key + "==" + value);
        }

        System.out.println("================");
        //使用entrySet遍历;
        Set<Map.Entry<String, String>> entry = map.entrySet();
        for (Map.Entry<String, String> s : entry) {
            String key = s.getKey();
            String value = s.getValue();
            System.out.println(key + "==" + value);
        }
    }
}
